from typing import *


class Solution:

    def maximumBeauty(self, nums: List[int], k: int) -> int:
        mx = max(nums)
        f = [0] * (mx + 1)
        for num in nums:
            f[max(num - k, 0)] += 1
            if num + k + 1 <= mx:
                f[num + k + 1] -= 1
        ans = v = 0
        for num in f:
            v += num
            ans = max(ans, v)

        return ans

s  = Solution()
print(s.maximumBeauty([13,46,71],29))
print(s.maximumBeauty([0],1))